#include <iostream>
using namespace std;

void devide(int t)
{
    int s = t;
    for (int i = 2; i <= t / i; ++i)
    {
        int num = 0;
        // 这里不需要跳过非质因数
        while (s % i == 0)
        {
            s /= i;
            ++num;
        }
        if (num)
            cout << i << ' ' << num << endl;
    }
    if (s != 1)
        cout << s << ' ' << '1' << endl;
    cout << endl;
}

int main()
{
    int n, t;
    cin >> n;
    while (n--)
    {
        cin >> t;
        devide(t);
    }
    return 0;
}
